package com.wing.cabinet.controller.app;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.log.Log;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wing.common.utils.HttpHelper;
import com.wing.common.utils.JsonResult;
import com.wing.common.utils.PageResult;
import com.wing.platform.feign.PlatformClient;
import com.wing.platform.order.model.entity.SysSettingAdvert;
import com.wing.platform.order.model.entity.Version;
import com.wing.platform.order.model.request.VersionForm;
import com.wing.platform.order.model.response.SysSettingForm;
import com.wing.platform.order.model.response.SysSettingVO;
import com.wing.web.annotation.RequestObjectFieldIgnore;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Validated
@Api(value = "Admin-APP端版本管理表管理", tags = "#/version/version")
@RestController("versionController")
@RequestMapping("version/app/version")
@RequiredArgsConstructor
public class VersionController {

    @Autowired
    private PlatformClient platformClient;

    @Value("${platform.gatewayUrl}")
    private String url;
    /**
     * 查询所有版本
     * @return
     */
    @GetMapping("/versionList")
    public JsonResult<List<Version>> versionList(@RequestParam("type") String type) {
        return JsonResult.success(platformClient.versionList(type));
    }

    /**
     * 根据type 查询所有版本
     */
    @GetMapping("/getVersion")
    public JsonResult<Version> getVersion(String channelCode,@RequestParam("type") String type,@RequestParam(value = "enterpriseId",required = false)String enterpriseId){
        try {
//            String s = HttpHelper.httpGet(url + "/platform/version/app/version/getVersion?type=" + type + "&enterpriseId=" + enterpriseId);
            String s = HttpHelper.httpGet(url + "/supplier/version/app/version/getVersion?type=" + type + "&enterpriseCode=" + channelCode);
//            JSONObject jsonObject = JSONObject.parseObject(s);
//            String data = jsonObject.getString("data");
            JsonResult<Version> data = JSONObject.parseObject(s, JsonResult.class);
//            Version version= JSONObject.parseObject(JSONObject.toJSONString(data.getData()),Version.class);
//            List<Version> list=new ArrayList<>();
//            list.add(version);
//            return JsonResult.success(list);
            return data;
        }catch (Exception e){
//            e.printStackTrace();
            log.error("getVersion err",e);
            return JsonResult.fail(e.getMessage());
        }

//        return platformClient.getVersion(type,enterpriseId);
    }

    /**
     * 修改
     */
/*    @ApiOperation(value = "修改APP端版本管理表", notes = "修改")
    @PutMapping("/update")
    public JsonResult update(@RequestBody VersionForm versionForm) {
        JsonResult<VersionForm> result = platformClient.updateVersion(versionForm);
        if (result.getCode()==200){
            return result;
        }
        return result;
    }*/

    /**
     * 添加
     * @param versionForm APP端版本管理表
     * @return
     */
/*    @PostMapping("/add")
    public JsonResult add(@RequestBody VersionForm versionForm) {
        JsonResult<VersionForm> result = platformClient.addVersion(versionForm);
        if (result.getCode()==200){
            return result;
        }else {
            return result;
        }
    }*/



}
